package com.tkjt.pms.modules.kpiAudit.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.tkjt.pms.modules.kpiAudit.model.kpiAuditrowList.KpiAuditrowListModel;
import com.tkjt.pms.modules.kpiAudit.model.vo.AuditStatisticsVO;
import com.tkjt.pms.modules.kpiAudit.service.KpiAuditService;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/api/kpiAudit/apply")
public class KpiAuditApplyController {


    @Autowired
    KpiAuditService kpiAuditService;
    /**
     * 申请列表/核批列表/
     * @return
     */
    @GetMapping("/list")
    public Result<?> getList(HttpServletRequest request) {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if(loginUser==null) {
            return Result.error("用户非法！");
        }
        try {
            KpiAuditrowListModel model = kpiAuditService.getKpiAuditrowListModel(loginUser,request);
            return Result.ok(model);
        }catch (Exception e){e.printStackTrace();
            return Result.error("获取数据异常");
        }

    }

    /**
     * 详情
     * @return
     */
    @GetMapping("/commentsDatagrid")
    public Result<?> commentsDatagrid(HttpServletRequest request) {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if(loginUser==null) {
            return Result.error("用户非法！");
        }
        try {
            List<AuditStatisticsVO> list = kpiAuditService.getAuditStatisticsVOList(loginUser,request);
            return Result.ok(list);
        }catch (Exception e){e.printStackTrace();
            return Result.error("获取数据异常");
        }

    }

    //submitAudit

    /**
     * 提交审核/审核/回退
     * @param request
     * @return
     */
    @GetMapping("/submitAudit")
    public Result<?> submitAudit(HttpServletRequest request) {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if(loginUser==null) {
            return Result.error("用户非法！");
        }
        try {
            String message = kpiAuditService.toSubmitAudit(loginUser,request);
            log.info("=============submitAudit:"+message);
            return Result.ok(message);
        }catch (Exception e){e.printStackTrace();
            return Result.error("获取数据异常");
        }
    }
}
